import { defineStore } from 'pinia'
export const modalStore = defineStore('modal', {
    state: () => ({ title: "", content: '', show: false, resolve: null, reject: null }),
    actions: {
        Modal(obj) {
            this.title = obj.title || '提示'
            this.content = obj.content
            this.show = true
            return new Promise((resolve) => {
                this.resolve = resolve
            })
        },
        showModal(content) {
            return this.Modal({ content })
        },
        close(result) {
            if (result === 'confirm') {
                this.resolve({ confirm: true, cancel: false })
            }
            else if (result === 'cancel') {
                this.resolve({ confirm: false, cancel: true });
            }
            this.show = false
            this.resolve = null
        }
    }

})

export default modalStore